package com.photoeditor.demo.ui.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.photoeditor.R;


public class NormalDialog extends BaseDialog {
    private View mBtnDivider, mDivider;

    public NormalDialog(Context context) {
        super(context);
    }

    public NormalDialog(Context context, int theme) {
        super(context, theme);
    }

    protected NormalDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    public void initDefaultView(Context context) {
        super.initDefaultView(context);
        setContentView(R.layout.dialog_normal_layout);
        mRootView = findViewById(R.id.dialog_theme_root);
        mBtnDivider = findViewById(R.id.btn_divider);
        mDivider = findViewById(R.id.divider);
        mTitle = (TextView) findViewById(R.id.title);
        mContent = (TextView) findViewById(R.id.message);
        mPositiveButton = (Button) findViewById(R.id.ok);
        mNegativeButton = (Button) findViewById(R.id.cancel);
    }

    public void setTitleText(String title) {
        if (!TextUtils.isEmpty(title)) {
            mTitle.setVisibility(View.VISIBLE);
            mTitle.setText(title);
        } else {
            mTitle.setVisibility(View.GONE);
        }
    }

    public void setTitleTextSize(int size) {
        mTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
    }

    public void setContent(String contentText) {
        if (!TextUtils.isEmpty(contentText)) {
            mContent.setVisibility(View.VISIBLE);
            mContent.setText(contentText);
        } else {
            mContent.setVisibility(View.GONE);
        }
    }


    public void setTitleColor(int color) {
        mTitle.setTextColor(color);
    }

    public void setContentText(String title) {
        mContent.setText(title);
    }

    public void setContentColor(int color) {
        mContent.setTextColor(color);
    }

    public void setContentSize(float size) {
        mContent.setTextSize(size);
    }


    public void showNegativeBtn(boolean show) {
        if (mNegativeButton == null) {
            return;
        }
        mNegativeButton.setVisibility(!show ? View.GONE : View.VISIBLE);
        mBtnDivider.setVisibility(!show ? View.GONE : View.VISIBLE);
    }

    /**
     * 这里用的是View下的onclicklistener,需要自己手动dimiss这个dialog
     *
     * @param text
     * @param listener
     */
    public Button setPositiveBtn(String text, View.OnClickListener listener) {
        if (!TextUtils.isEmpty(text)) {
            mPositiveButton.setText(text);
        }
        if (null != listener) {
            mPositiveButton.setOnClickListener(listener);
        } else {
            mPositiveButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                }
            });
        }
        return mPositiveButton;
    }

    public Button setNegativeBtn(String text, View.OnClickListener listener) {
        if (!TextUtils.isEmpty(text)) {
            mNegativeButton.setText(text);
        }
        if (null != listener) {
            mNegativeButton.setOnClickListener(listener);
        } else {
            mNegativeButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                }
            });
        }
        return mNegativeButton;
    }


}
